import {acceptHMRUpdate, defineStore} from 'pinia';

import type {BasicUserInfo} from '#/typings';

interface UserInfo extends BasicUserInfo {

}

interface AccessState {
    /**
     * 用户信息
     */
    userInfo: UserInfo | null;
}

/**
 * @zh_CN 用户信息相关
 */
export const useUserStore = defineStore('core-user', {
    actions: {
        setUserInfo(userInfo: UserInfo | null) {
            // 设置用户信息
            this.userInfo = userInfo;
        },
    },
    state: (): AccessState => ({
        userInfo: null,
    }),
});

// 解决热更新问题
const hot = import.meta.hot;
if (hot) {
    hot.accept(acceptHMRUpdate(useUserStore, hot));
}